// #include "mlir/InitAllTranslations.h"
// #include "mlir/Support/LogicalResult.h"
#include "mlir/Tools/mlir-translate/MlirTranslateMain.h"

#include "mlir/IR/BuiltinOps.h"
#include "mlir/Target/LLVMIR/Dialect/All.h"
#include "mlir/Target/LLVMIR/Export.h"
#include "mlir/Tools/mlir-translate/Translation.h"
// #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"


using namespace mlir;

int main(int argc, char **argv) {

  TranslateFromMLIRRegistration registration(
      "wafer-to-llvmir", "translate MLIR from wafer toolchain to LLVM IR",
      [](ModuleOp module, raw_ostream &output) {
        llvm::LLVMContext llvmContext;
        auto llvmModule = translateModuleToLLVMIR(module, llvmContext);
        if (!llvmModule)
          return failure();

        llvmModule->print(output, nullptr);
        return success();
      },
      [](DialectRegistry &registry) {
        // Register translation in upstream MLIR.
        registerArmNeonDialectTranslation(registry);
        registerAMXDialectTranslation(registry);
        registerArmSVEDialectTranslation(registry);
        registerLLVMDialectTranslation(registry);
        registerNVVMDialectTranslation(registry);
        registerOpenACCDialectTranslation(registry);
        registerOpenMPDialectTranslation(registry);
        registerROCDLDialectTranslation(registry);
        registerX86VectorDialectTranslation(registry);
        registerAllToLLVMIRTranslations(registry);
        // Register translation in wafer project.
      });

  return failed(mlir::mlirTranslateMain(argc, argv, "Wafer Translation Tool"));
}
